package com.handong.handserialprogram.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.handong.handserialprogram.R;
import com.handong.handserialprogram.utils.JLog;
import com.handong.handserialprogram.voice.VoiceImpl;

/**
 * Created by userKey on 2017/11/21.
 */

public class BatteryBroadcastReceiver extends BroadcastReceiver {

    private static final String TAG = BatteryBroadcastReceiver.class.getSimpleName();
    private int mBatteryLevel = 0;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
            int level = intent.getIntExtra("level", 0);
            //JLog.d(TAG, "The New Level:" + level);
            if (mBatteryLevel == level) {
                return;
            }
            JLog.d(TAG, "Last Battery Level:" + mBatteryLevel);
            mBatteryLevel = level;
            if (level == 29 || level == 19 || level == 10) {
                VoiceImpl impl = VoiceImpl.getInstance(context);
                //低电量报警。
                impl.playHighPriority(R.raw.warning_phone_low_battery);
            }
        }
    }
}
